package cn.legend.travel.basic.info.controller;

import cn.legend.travel.basic.info.pojo.param.AvatarParam;
import cn.legend.travel.basic.info.pojo.param.UpdateInfoParam;
import cn.legend.travel.basic.info.pojo.vo.BlackListVO;
import cn.legend.travel.basic.info.pojo.vo.UserInfoVO;
import cn.legend.travel.basic.info.service.UserService;
import cn.legend.travel.common.pojo.authentication.CurrentPrincipal;
import cn.legend.travel.common.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

@Api(tags = "1.用户信息管理")
@RestController
@RequestMapping("/users/info/")
public class UserController {
    @Autowired
    private UserService userService;

    @ApiOperation("根据ID查找用户信息")
    @ApiOperationSupport(order = 1)
    @GetMapping("{id}/get-info-by-id")
    public JsonResult getUserInfoById(@PathVariable Long id){
        UserInfoVO userInfoVO = userService.getUserInfoById(id);
//        System.out.println(userInfoVO);
        return JsonResult.ok(userInfoVO);
    }

    @ApiOperation("插入黑名单")
    @ApiOperationSupport(order = 1)
    @PostMapping("add-black-list")
    public JsonResult insertBatchBlack(List<Long> idList,@AuthenticationPrincipal CurrentPrincipal principal){
        System.out.println("黑名单idList:"+idList);
        userService.insertBlack(idList,principal);

        return JsonResult.ok();
    }

    @ApiOperation("根据nickname查找用户信息")
    @ApiOperationSupport(order = 1)
    @GetMapping("{nickname}/get-info-by-nickname")
    public JsonResult getUserInfoByNickname(@PathVariable String nickname){
        System.out.println("nickname:"+nickname);
        List<BlackListVO> userInfoVOS = userService.selectUserInfoByNickname(nickname);
//        System.out.println(userInfoVO);
        return JsonResult.ok(userInfoVOS);
    }

    @ApiOperation("根据ID修改用户信息")
    @ApiOperationSupport(order = 2)
    @PostMapping ("update-info-by-id")
    public JsonResult updateUserInfoByUser(@Validated @RequestBody UpdateInfoParam updateInfoParam,
                                      @AuthenticationPrincipal @ApiIgnore CurrentPrincipal principal){
        System.out.println("收到用户信息："+ updateInfoParam);
        int rows = userService.updateUserInfoByUser(updateInfoParam, principal);
        System.out.println("受影响行数"+rows);
        return JsonResult.ok();
    }

    @ApiOperation("根据ID修改用户头像")
    @ApiOperationSupport(order = 3)
    @PostMapping ("update-avatar")
    public JsonResult updateAvatar(@RequestBody AvatarParam param,
                                           @AuthenticationPrincipal @ApiIgnore CurrentPrincipal principal){
        System.out.println("收到用户头像："+ param);
        int rows = userService.updateAvatar(param.getAvatar(), principal);
        System.out.println("受影响行数"+rows);
        return JsonResult.ok();
    }







}
